package com.chb.microservice.provider.hystrix;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cbh.api.model.ApiResult;
import com.chb.microservice.provider.feign.ProductFeignClient;
import com.chb.microservice.provider.model.Product;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class ProductHystrixWrapped {

	@Autowired
	private ProductFeignClient productFeignClient;

	/**
	 * 保存产品信息
	 * 
	 * @param product
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<String> save(Product ob) {
		return productFeignClient.save(ob);
	}

	public ApiResult<String> fallBackCall(Product ob) {
		return new ApiResult<String>().fail("调用报错");
	}

	/**
	 * 获取全部产品信息
	 * 
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<List<Product>> getAll() {
		return productFeignClient.getAll();
	}

	public ApiResult<List<Product>> fallBackCall() {
		return new ApiResult<List<Product>>().fail("调用报错");
	}

	/**
	 * 获取产品信息
	 * 
	 * @param proId
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<Product> getOne(String id) {
		return productFeignClient.getOne(id);
	}

	public ApiResult<Product> fallBackCall(String id) {
		return new ApiResult<Product>().fail("调用报错");
	}
}
